package org.gd136.ce.stage;

import org.gd136.ce.action.CallAction;
import org.gd136.ce.manager.RM;
import org.gd136.ce.util.U;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Align;

public class LogoLayer extends Layer {

	Texture circle;
	Image ac;
	Image tw, tb;

	float mm = 250;// 150f;
	float m = 178; // 90f;
	// float ox = 2.4f, oy = 29.4f;
	float ox = 0, oy = 0;
	float txtH = 0; // 44f;

	public LogoLayer() {
		Image bk = RM.colorImage();
		bk.setSize(getWidth(), getHeight());
		addActor(bk);

		// //////
		tb = RM.colorImage();
		tb.setColor(Color.BLACK);
		tb.setSize(getWidth(), txtH);
		tb.setOrigin(Align.center);
		tb.setScaleY(0);
		addActor(tb);
		tb.setPosition(getWidth() / 2, getHeight() / 2 - 105, Align.center);
		tb.addAction(Actions.sequence(Actions.delay(3f),
				Actions.scaleTo(1, 1, 0.4f)));

		tb.setVisible(false);
		// //////
		Image logo = image("G136E.png");
		addActor(logo);

		logo.setPosition(getWidth() / 2, getHeight() / 2, Align.center);
		logo.getColor().a = 0;
		logo.addAction(Actions.sequence(Actions.fadeIn(0.5f),
				Actions.delay(6f), CallAction.create(() -> {
					U.transLayer(LogoLayer.this, new TitleLayer());
				})));
		// ///////
		tw = RM.colorImage();
		tw.setSize(getWidth(), txtH);
		addActor(tw);
		tw.setPosition(getWidth() / 2, tb.getY() + tb.getHeight() / 2,
				Align.center);
		tw.addAction(Actions.sequence(Actions.delay(3f), Actions.fadeOut(1.5f)));
		// ///////////

		Pixmap pix = new Pixmap(1024, 1024, Format.RGBA8888);
		pix.setColor(0, 0, 0, 0);
		pix.fill();
		pix.setColor(52f / 255, 168f / 255, 83f / 255, 1);
		pix.fillCircle(pix.getWidth() / 2, pix.getHeight() / 2,
				pix.getWidth() / 2 - 2);
		circle = new Texture(pix);
		pix.dispose();

		ac = new Image(circle);
		addActor(ac);
		ac.setPosition(getWidth() / 2 + ox, getHeight() / 2 + oy, Align.center);
		ac.setScale(2);
		ac.setOrigin(Align.center);

		ac.addAction(Actions.sequence(Actions.scaleTo(mm / 1024, mm / 1024,
				1.0f, Interpolation.circle), Actions.scaleTo(mm / 1024 + 0.05f,
				mm / 1024 + 0.05f, 0.6f, Interpolation.circle), Actions
				.parallel(Actions.scaleTo(m / 1024, m / 1024, 0.3f,
						Interpolation.circle), Actions.color(new Color(
						99f / 255, 234f / 255, 131f / 255, 1), 0.3f)), Actions
				.fadeOut(1.5f)));

		// ///
		Image mask = U.createMask(this);
		this.addActor(mask);
		mask.addAction(Actions.fadeOut(0.5f));
	}

	@Override
	public void dispose() {
		circle.dispose();
		super.dispose();
	}

}
